using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace UGed
{
   internal class Ancestors
   {
      private Individuals myIndviduals = null;
      private Families myFamilies = null;
      private string individualA = "";
      private string individualB = "";
      private List<Ancestor> ancestorsA = new List<Ancestor>();
      private List<Ancestor> ancestorsB = new List<Ancestor>();
      static string _currentIndividual;


      /// <summary>
      /// create a new anscestors object and pass an individuals collection and a families collection
      /// </summary>
      /// <returns>nothing</returns>
      public Ancestors(Individuals individuals, Families families)
      {
         myIndviduals = individuals;
         myFamilies = families;
      }

      /// <summary>
      /// create a new anscestors object and pass an individuals collection and a families collection
      /// </summary>
      /// <returns>nothing</returns>
      public Ancestors(Individuals individuals, Families families, string FocusIndividual)
      {
         myIndviduals = individuals;
         myFamilies = families;
         individualA = FocusIndividual;
      }

      public string IndividualA
      {
         get
         {
            return individualA;
         }
         set
         {
            individualA = value;
         }
      }

      public string IndividualB
      {
         get
         {
            return individualB;
         }
         set
         {
            individualB = value;
         }
      }

      private bool GetAncestorsA(string id)
      {
         //build an array list of ancestors for a
         Individual i = null;
         bool bret = false;
         Ancestor a = new Ancestor();
         string nextID = "";

         try
         {
            i = myIndviduals[id];
         }
         catch
         {
            i = null;
         }

         if (i == null) return false;
         a.ID = id;
         nextID = "";
         a.Generation = 0;
         a.FamilyID = i.FamilyID;
         a.Sex = i.Sex;
         a.DidFollow = false;

         a.FatherID = myFamilies[i.FamilyID].Husband;
         if (a.FatherID != "?") nextID = a.FatherID;
         a.MotherID = myFamilies[i.FamilyID].Wife;
         if (a.MotherID != "?" && nextID == "") nextID = a.MotherID;

         ancestorsA.Add(a);
         bret = true;

         while (nextID != "")
         {

            nextID = GetNextID(ancestorsA);
         }
         
         return bret;
      }

      private string GetNextID(List<Ancestor> ancestorList)
      {
         foreach (Ancestor a in ancestorList)
         {

         }

         return ""; //temporary so will compile
      }

      
      private void GetAncestorsB()
      {
         //build an array list of ancestors for b
      }

      private bool FindCommonAncestor(ref string IndiID, ref int NumGenerations)
      {
         bool bret = false;

         return bret;
      }

      /// <returns>string</returns>
      public string CalcRelationship()
      {
         string relationString = "";

         return relationString;
      }

   }

   internal class Ancestor
   {
      public string ID = "";
      public int Generation = 0;
      public string Sex = "U";
      public string FamilyID = "";
      public string MotherID = "?";
      public string FatherID = "?";
      public bool DidFollow = false;
   }
}
